<?php

	eb_include_module_file("Core/ObjectModel");

	class UrlRouteModel extends ObjectModel
	{
		private $mapPageRoutes;
			
		public function __construct()
		{
			parent::init('eb_urlroute','Core/UrlRouteVO','ur_id');
		}
				
		public function getColumns()
		{
			return array(
				new EbTableColumn("ur_id","int",false,EB_PRIMARY_KEY,true),
				new EbTableColumn("ob_id","int",true,EB_INDEX_KEY),
				new EbTableColumn("url","varchar(256)",true,EB_UNIQUE_KEY),
				new EbTableColumn("type","tinyint",true,EB_INDEX_KEY),
				new EbTableColumn("data","varchar(256)",false)
			);
		}		
		
		public function create()
		{
			if (parent::create())
			{
				$this->insert(array("name" => "home","url" => "","type" => 1));
				$this->insert(array("name" => "404","url" => "404","type" => 1, 'data' => 'module:Core;file:404Page'));
				$this->insert(array("name" => "login","url" => "login","type" => 1, 'data' => 'module:Core;file:loginPageComponent'));
				$this->insert(array("name" => "ebAmfAdmin","url" => "amfadmingateway","type" => 2,"data" => "module=Core;file=AmfAdminGateway;"));
				$this->insert(array("name" => "ebAdmin","url" => "eb-admin","type" => 1, "roles" => 2, "data" => "module:Core;file:adminPage;"));
				$this->insert(array("name" => "defaultModelAccess","url" => "<module>/model-<file>/<method>.<output>","type" => 0));
				$this->insert(array("name" => "coreCommandAccess","url" => "Core/<file>.do","type" => 2, "data" => "module:Core"));
			}
		}
		
		public function selectPrepared($whereClause = null)
		{
			$buffer = parent::select($whereClause,'CHAR_LENGTH(url) DESC');
					
			foreach ($buffer AS &$item)
			{				
				$item->data = eb_parse_parameters_string($item->data);
			}
									
			return $buffer;
		}
	}	